package crm.salesOrderProcessing.entity;

import crm.clientManagement.entity.CompanyEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 *
 * @author frankxgz
 */
@Entity
public class SalesQuotationEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Temporal(value = TemporalType.DATE)
    private Date validUntil;
    private double userDiscount;
    private double totalPrice;
    @Temporal(value = TemporalType.DATE)
    private Date raiseDate;
    private int leadTime;
    
    private String processedBy;
    private boolean used;
    
    @ManyToOne 
    private CompanyEntity company;
    
    @OneToMany(targetEntity = LineItemEntity.class ,cascade={CascadeType.PERSIST})
    private List<LineItemEntity> quotationLineItems = new ArrayList<LineItemEntity>();
    
    
    
    public boolean isExpired(){
        
        if (Calendar.getInstance().getTime().after(validUntil)){
            return true;
        }
        return false;
    }
    
    
    
    public SalesQuotationEntity(){
        setId(System.nanoTime());
    }
    
    public void create(Date validUntil, Long totalPrice){
        this.setValidUntil(validUntil);
        this.setTotalPrice(totalPrice);
    }
    
    public double getTotalPrice(){ return totalPrice;}
    public void setTotalPrice(double totalPrice){
        this.totalPrice=totalPrice;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getValidUntil() {
        return validUntil;
    }

    public void setValidUntil(Date validUntil) {
        this.validUntil = validUntil;
    }
    
    public double getUserDiscount(){
        return this.userDiscount;
    }

    public void setUserDiscount(double userDiscount){
        this.userDiscount=userDiscount;
    }
    public CompanyEntity getCompany() {
        return company;
    }

    public void setCompany(CompanyEntity company) {
        this.company = company;
    }

    public List<LineItemEntity> getQuotationLineItems() {
        return quotationLineItems;
    }

    public void setQuotationLineItems(List<LineItemEntity> quotationLineItems) {
        this.quotationLineItems = quotationLineItems;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SalesQuotationEntity)) {
            return false;
        }
        SalesQuotationEntity other = (SalesQuotationEntity) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "sales.entity.SalesQuotation[ id=" + getId() + " ]";
    }

    public Date getRaiseDate() {
        return raiseDate;
    }

    public void setRaiseDate(Date raiseDate) {
        this.raiseDate = raiseDate;
    }

    public boolean isUsed() {
        return used;
    }

    public void setUsed(boolean used) {
        this.used = used;
    }

    /**
     * @return the leadTime
     */
    public int getLeadTime() {
        return leadTime;
    }

    /**
     * @param leadTime the leadTime to set
     */
    public void setLeadTime(int leadTime) {
        this.leadTime = leadTime;
    }

    /**
     * @return the processedBy
     */
    public String getProcessedBy() {
        return processedBy;
    }

    /**
     * @param processedBy the processedBy to set
     */
    public void setProcessedBy(String processedBy) {
        this.processedBy = processedBy;
    }

   
 
    
}
